Skip to content

Refactor#42

Merged
dex3r merged 3 commits into
mainfrom
refactor
Mar 3, 2026
Merged

Refactor#42
dex3r merged 3 commits into
mainfrom
refactor

Conversation

@dex3r
Copy link
Copy Markdown
Owner

@dex3r dex3r commented Mar 3, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 3, 2026 17:08
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 28.57143% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...Helpers.Abstractions/RecordingGeneratorsFactory.cs 8.10% 34 Missing ⚠️
MattSourceGenHelpers.Abstractions/Mocks.cs 0.00% 15 Missing ⚠️
MattSourceGenHelpers.Abstractions/MethodBuilder.cs 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@dex3r dex3r merged commit f67b905 into main Mar 3, 2026
3 checks passed
@dex3r dex3r deleted the refactor branch March 3, 2026 17:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the source generation helper library by reorganizing and simplifying the fluent API's generator infrastructure. The primary goal is to decouple the recording and mock implementations, make Generate.CurrentGenerator internal (using reflection to set it during generation), and introduce a proper IMethodBuilder interface alongside IGeneratorsFactory. It also adds two new test cases covering default-case constant-value generation via both the attribute-based and fluent APIs.

Changes:

  • Extracted interfaces IMethodBuilder, IMethodBuilder<TArg1>, and IGeneratorsFactory into separate files; moved MethodBuilder implementations to their own file.
  • Replaced the EmptyGeneratorsFactory-based default in Generate.CurrentGenerator with a new no-op MockGeneratorsFactory, and changed the property from public to internal (updating the generator's reflection binding flags accordingly).
  • Removed the Integer.Range helper; callers now pass plain arrays. Added new tests (DefaultCaseConstValue, DefaultCaseConstValueFluent) covering the default-case-only switch generation path.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
MattSourceGenHelpers.Abstractions/Generate.cs Slimmed down: removed inlined interfaces/classes; CurrentGenerator changed to internal with MockGeneratorsFactory default
MattSourceGenHelpers.Abstractions/IGeneratorsFactory.cs New file: extracted IGeneratorsFactory interface (added ForMethod(), removed non-generic CreateImplementation())
MattSourceGenHelpers.Abstractions/IMethodBuilder.cs New file: extracted IMethodBuilder and IMethodBuilder<TArg1> interfaces
MattSourceGenHelpers.Abstractions/MethodBuilder.cs New file: extracted MethodBuilder and MethodBuilder<TArg1> implementations
MattSourceGenHelpers.Abstractions/Mocks.cs New file: MockGeneratorsFactory and mock chain as no-op runtime implementations
MattSourceGenHelpers.Abstractions/RecordingGeneratorsFactory.cs Refactored to use primary constructors and added ForMethod() delegation; recording classes simplified
MattSourceGenHelpers.Abstractions/Assembly.cs New file: InternalsVisibleTo for Tests and Generators assemblies
MattSourceGenHelpers.Abstractions/SwitchCase.cs Reformatted and made arg1 required (breaking change)
MattSourceGenHelpers.Abstractions/IMethodImplementationGenerator.cs Removed unused IMethodImplementationGeneratorVoid interface; added [UsedImplicitly]
MattSourceGenHelpers.Abstractions/IMethodGenerator.cs Deleted empty interface
MattSourceGenHelpers.Abstractions/Integer.cs Deleted Integer.Range helper
MattSourceGenHelpers.Abstractions/PartialMethodCalledDuringGenerationException.cs Converted to primary constructor syntax
MattSourceGenHelpers.Generators/GeneratesMethodExecutionRuntime.cs Updated reflection binding flags to NonPublic for CurrentGenerator; used nameof for property reflection lookups
MattSourceGenHelpers.Tests/DefaultCaseConstValue.cs New test file: attribute-based default-case constant-value generation
MattSourceGenHelpers.Tests/DefaultCaseConstValueFluent.cs New test file: fluent-API default-case constant-value generation
MattSourceGenHelpers.Tests/PiExampleFluentTests.cs Replaced Integer.Range(300, 303) with inline array new[]{300, 301, 302, 303}
MattSourceGenHelpers.Examples/PiExampleFluent.cs Same Integer.Range → inline array replacement in example
MattSourceGenHelpers.sln.DotSettings.user IDE user settings update (session ID change, 5 extra blank lines)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[UsedImplicitly]
public List<object> CaseKeys { get; } = new();
[UsedImplicitly]
public List<object?> CaseValues { get; } = new();
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasDefaultCase is accessed via reflection (in GeneratesMethodExecutionRuntime.cs line 290) just like CaseKeys and CaseValues, yet it is missing the [UsedImplicitly] annotation that was added to the other two properties. This is inconsistent and may cause a JetBrains inspection warning on HasDefaultCase.

Suggested change
public List<object?> CaseValues { get; } = new();
public List<object?> CaseValues { get; } = new();
[UsedImplicitly]

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +63
public IMethodImplementationGenerator<TReturnType> WithReturnType<TReturnType>() => new MockImplementationGenerator<TReturnType>();
}

public class MockImplementationGenerator<TReturnType> : IMethodImplementationGenerator<TReturnType>
{
public IMethodImplementationGenerator UseBody(Func<object> body) => this;
}

Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two classes implementing IMethodImplementationGenerator<TReturnType> with nearly identical implementations but different names: MockMethodImplementationGenerator<TReturnType> (line 13) and MockImplementationGenerator<TReturnType> (line 59). The second is used by MockMethodBuilder.WithReturnType<TReturnType>() but could simply reuse MockMethodImplementationGenerator<TReturnType>, eliminating the duplication and inconsistent naming.

Suggested change
public IMethodImplementationGenerator<TReturnType> WithReturnType<TReturnType>() => new MockImplementationGenerator<TReturnType>();
}
public class MockImplementationGenerator<TReturnType> : IMethodImplementationGenerator<TReturnType>
{
public IMethodImplementationGenerator UseBody(Func<object> body) => this;
}
public IMethodImplementationGenerator<TReturnType> WithReturnType<TReturnType>() => new MockMethodImplementationGenerator<TReturnType>();
}

Copilot uses AI. Check for mistakes.
object? arg1 = null
)
: Attribute
public class SwitchCase(object? arg1) : Attribute
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arg1 parameter of SwitchCase was previously optional (object? arg1 = null). In this PR it is now required (object? arg1). Since SwitchCase is a public attribute, this is a breaking API change for any external consumer using [SwitchCase] without an argument. If this attribute is intended to be a public API, consider documenting this breaking change or preserving the optional default.

Suggested change
public class SwitchCase(object? arg1) : Attribute
public class SwitchCase(object? arg1 = null) : Attribute

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +21





Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Five extra blank lines (lines 17–21) were added to the <wpf:ResourceDictionary> XML element. These are stale IDE artifacts and add no value. They should be removed to keep the settings file clean.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +20
public void PiExampleLikeGenerator_ProducesExpectedRuntimeOutput(int decimalNumber, int expectedDigit)
{
int result = DefaultCaseConstValueClass.Foo(decimalNumber);

Assert.That(result, Is.EqualTo(expectedDigit));
}

[Test]
public void PiExampleLikeGenerator_ProducesExpectedGeneratedCode()
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test methods in both DefaultCaseConstValue and DefaultCaseConstValueFluent are named PiExampleLikeGenerator_ProducesExpectedRuntimeOutput and PiExampleLikeGenerator_ProducesExpectedGeneratedCode, which appear to be copied from the Pi example tests. These tests have nothing to do with the Pi example — they test default-case constant-value generation. The method names should be updated to reflect what's actually being tested (e.g., DefaultCaseWithConstValue_ProducesExpectedRuntimeOutput / DefaultCaseWithConstValue_ProducesExpectedGeneratedCode).

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +20
public void PiExampleLikeGenerator_ProducesExpectedRuntimeOutput(int decimalNumber, int expectedDigit)
{
int result = DefaultCaseConstValueFluentClass.Foo(decimalNumber);

Assert.That(result, Is.EqualTo(expectedDigit));
}

[Test]
public void PiExampleLikeGenerator_ProducesExpectedGeneratedCode()
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test methods in DefaultCaseConstValueFluent are named PiExampleLikeGenerator_ProducesExpectedRuntimeOutput and PiExampleLikeGenerator_ProducesExpectedGeneratedCode, which appear to be copied from the Pi example tests. These tests have nothing to do with Pi — they test default-case constant-value generation using the fluent API. The method names should be updated to reflect what's actually being tested (e.g., DefaultCaseWithConstValue_ProducesExpectedRuntimeOutput / DefaultCaseWithConstValue_ProducesExpectedGeneratedCode).

Copilot uses AI. Check for mistakes.
Comment on lines 18 to 23
public IMethodImplementationGenerator CreateImplementation()
{
var record = new SwitchBodyRecord();
SwitchBodyRecord record = new SwitchBodyRecord();
LastRecord = record;
return new RecordingMethodImplementationGenerator(record);
return new RecordingMethodImplementationGenerator();
}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-generic CreateImplementation() method in RecordingGeneratorsFactory is no longer part of the IGeneratorsFactory interface (which was updated in this PR to remove the non-generic overload) and is never called anywhere in the codebase. This is dead code that should be removed to avoid confusion.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants